// pages/personal/personal.ts
import { getPublicPaddingTopNumber } from '../../utils/page'
import { useLogin, getPersonalInformation, pubInfo } from '../../utils/controller'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    nickname: '',
    age: '',
    height: '',
    weight: '',
    paddingTop: getPublicPaddingTopNumber() + 20 + 'px',
    dialogVisible: false,
    hasLogin: false,
    head_img:'',
    access_count:0,
    collect_count:0,
    hand_count:0,
    visible2:false,
    kefu:'',
    age1:'',
    is_member:"",
    id:'',
    status:'',
    sex:'',
    statusText:['待审核','审核成功','审核失败']
  },
  goUrl(e){
    const index = e.currentTarget.dataset.index
    if(index == 1){
      wx.navigateTo({
        url:'/pages/agreement/marriage/marriage'
      })
    }else if(index == 2){
      wx.navigateTo({
        url:'/pages/information/information'
      })
    }
  },
  open2() {
    
    this.setData({
      visible2: true,
    })
  },
  close2() {
    this.setData({
      visible2: false,
    })
  },
  // 获取公共信息
  //1：隐私政策；2：注册协议；3：线下报名活动二维码；4：婚姻协议；5：防诈提示；6：关于我们；7联系客服
  async pubInfo(id){
    const res = await pubInfo({id})
    return res
  },
  async getKefu(){
    let kefu = await this.pubInfo(7)
    
    this.setData({
      kefu
    })
  },
  async handleGetPhoneNumber(e) {
    const _this = this
    console.log(e)
    const loginResult = await useLogin(e.detail.code)
    console.log('登录结果', loginResult)
    _this.setData({ hasLogin: true })
   this.getUserInfo()
  },

  async getUserInfo(){
    const personalInfoResult:any = await getPersonalInformation()
    if(personalInfoResult){
      this.setData({age:personalInfoResult.age, weight:personalInfoResult.weight, height:personalInfoResult.height, nickname:personalInfoResult.nickname, head_img:personalInfoResult.head_img, access_count: personalInfoResult.access_count,collect_count: personalInfoResult.collect_count, hand_count: personalInfoResult.hand_count,age1:personalInfoResult.age1,is_member:personalInfoResult.is_member,id:personalInfoResult.id,status:personalInfoResult.status,sex:personalInfoResult.sex})
      wx.setStorageSync('userInfo', JSON.stringify(personalInfoResult))
    }else{
      if (wx.getStorageSync('token')) {
        this.setData({ hasLogin: true })
      } else {
        this.setData({ hasLogin: false })
      }
    }
    
  },

  toAntiCheat() {
    // wx.showToast({ icon: 'none', title: '请提供公众号文章' })
    wx.navigateTo({
      url:'/pages/agreement/reminder/reminder'
    })
  },

  async showDialog() {
    this.setData({ dialogVisible: true })
  },

  hideDialog() {
    this.setData({ dialogVisible: false })
  },

  toEdit() {
    wx.navigateTo({ url: '../edit/edit' })
  },

  // 开通会员
  toVip() {
    wx.navigateTo({ url: '../vip/vip' })
  },

  // 设置按钮方法
  toSetting() {
    wx.navigateTo({ url: '../setting/setting' })
  },

  // 点击访问记录按钮方法
  toVisit() {
    wx.navigateTo({ url: '../visit/visit' })
  },

  // 点击收藏按钮方法
  toCollect() {
    wx.navigateTo({ url: '../favorite/favorite' })
  },

  // 点击拉手次数按钮方法
  toHand() {
    wx.navigateTo({ url: '../hand/hand' })
  },

  // 点击微信群按钮方法
  toGroup() {
    wx.navigateTo({ url: '../group/group' })
  },

  // 点击关于我们按钮方法
  toAboutUs() {
    wx.navigateTo({ url: '../aboutus/aboutus' })
  },

  // 点击隐私政策按钮方法
  toPrivacy() {
    wx.navigateTo({ url: '../agreement/privacy/privacy' })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    if (typeof this.getTabBar === 'function') {
      this.getTabBar((tabbar) => {
        tabbar.setData({
          selected: 2,
        })
      })
    }
    this.getKefu()
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  async onShow() {

    this.getUserInfo()
    if (wx.getStorageSync('token')) {
      this.setData({ hasLogin: true })
      
    } else {
      this.setData({ hasLogin: false })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
})
